from waveapi import events
from waveapi import model
from waveapi import robot

def OnParticipantsChanged(properties, context):
  """Invoked when any participants have been added/removed."""
  added = properties['participantsAdded']
  for p in added:
    Notify(context)

def OnRobotAdded(properties, context):
  """Invoked when the robot has been added."""
  root_wavelet = context.GetRootWavelet()
  root_wavelet.CreateBlip().GetDocument().SetText("Evento: El robot ha sido agregado")

def Notify(context):
  root_wavelet = context.GetRootWavelet()
  root_wavelet.CreateBlip().GetDocument().SetText("Evento: Notify")

def OnDocumentChanged(properties, context):
  """Invoked when document changes"""
  root_wavelet = context.GetRootWavelet()
  root_wavelet.CreateBlip().GetDocument().SetText("Evento: Hola Googlers. Happy coding!")
  
def Announce(context):
  root_wavelet = context.GetRootWavelet()
  root_wavelet.CreateBlip().GetDocument().SetText("Evento: Announce")
  
if __name__ == '__main__':
  
  myRobot = robot.Robot('lagunabot', 
      image_url='icon.png',
      version='1',
      profile_url='http://lagunabot.appspot.com/')
  myRobot.RegisterHandler(events.WAVELET_PARTICIPANTS_CHANGED, OnParticipantsChanged)
  myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded)  
  myRobot.RegisterHandler(events.DOCUMENT_CHANGED, OnDocumentChanged)
						
  myRobot.Run()
